package com.my.chapter7;

public class practice12 {
    public static void main(String[] args) {
        Stem2 s = new Stem2();
        s.dispose();
    }
}

class Component12{
    public Component12(){
        System.out.println("Component1 constructor");
    }
    public void dispose(){
        System.out.println("Component1 dispose");
    }
}

class Component22{
    public Component22(){
        System.out.println("Component2 constructor");
    }
    public void dispose(){
        System.out.println("Component2 dispose");
    }
}

class Component32{
    public Component32(){
        System.out.println("Component3 constructor");
    }
    public void dispose(){
        System.out.println("Component3 dispose");
    }
}

class Root2{
    private Component12 c1 =new Component12();
    private Component22 c2 =new Component22();
    private Component32 c3 =new Component32();
    public Root2(){
        System.out.println("Root constructor");
    }
    public void dispose(){
        c1.dispose();
        c2.dispose();
        c3.dispose();
        System.out.println("Root dispose");
    }
}

class Stem2 extends Root2{
    public Stem2(){
        System.out.println("Stem constructor");
    }
    public void dispose(){
        super.dispose();
        System.out.println("Stem dispose");
    }
}
